<template>
  <el-dialog :title="modelTitle" width="30%" :visible.sync="visible">
    <el-form ref="form" :model="form" class="dialog-form" label-position="right" label-width="120px">
      <el-form-item label="描述" prop="msg" :rules="self.page.rules.def">
        <el-input v-model="form.msg" type="textarea" :rows="2" placeholder="请输入描述" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取 消</el-button>
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: 'PurCanceling',
  props: {
    value: {
      type: String,
      default: ''
    },
    self: {
      type: Object,
      default: () => { return {} }
    }
  },
  data() {
    return {
      visible: false,
      form: {
        expensesId: 0,
        msg: ''
      },
      modelTitle: '',
      audioUrl: ''
    }
  },
  created() {
  },
  mounted() {
    this.form.expensesId = this.value
  },
  methods: {
    show(val) {
      console.log(val)
      if (val === 'canceling') {
        this.modelTitle = '取消订单'
        this.audioUrl = '/cancel'
      } else if (val === 'rejected') {
        this.modelTitle = '订单驳回'
        this.audioUrl = '/rejected'
      }
      this.visible = true
    },
    submit() {
      const that = this

      that.$refs['form'].validate((valid) => {
        if (!valid) {
          return
        }
        const loading = that.$loading()
        const url = that.self.page.router.remoteUrl + that.audioUrl
        that.self.service.post(url, that.form).then(res => {
          loading.close()
          if (res.code !== 200) {
            that.$message.error(res.message)
            return
          }
          that.$message.success('操作成功!')
          that.visible = false
          that.self.reload(true)
        }).catch((e) => {
          loading.close()
        })
      })
    }
  }
}
</script>
<style scoped>
.app-main .lola-container .edit-control form{
    padding-top: 0;
}
</style>
